package com.ruoyi.mes.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.mes.domain.MesDispatchWorkers;
import com.ruoyi.mes.service.IMesDispatchWorkersService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产员工Controller
 *
 * @author ruoyi
 * @date 2021-11-04
 */
@RestController
@RequestMapping("/dispatchWorkers")
public class MesDispatchWorkersController extends BaseController
{
    @Autowired
    private IMesDispatchWorkersService mesDispatchWorkersService;

    /**
     * 查询生产员工列表
     */
    @PreAuthorize(hasPermi = "mes:dispatchWorkers:list")
    @GetMapping("/list")
    public TableDataInfo list(MesDispatchWorkers mesDispatchWorkers)
    {
        startPage();
        List<MesDispatchWorkers> list = mesDispatchWorkersService.selectMesDispatchWorkersList(mesDispatchWorkers);
        return getDataTable(list);
    }

    /**
     * 导出生产员工列表
     */
    @PreAuthorize(hasPermi = "mes:dispatchWorkers:export")
    @Log(title = "生产员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesDispatchWorkers mesDispatchWorkers) throws IOException
    {
        List<MesDispatchWorkers> list = mesDispatchWorkersService.selectMesDispatchWorkersList(mesDispatchWorkers);
        ExcelUtil<MesDispatchWorkers> util = new ExcelUtil<MesDispatchWorkers>(MesDispatchWorkers.class);
        util.exportExcel(response, list, "生产员工数据");
    }

    /**
     * 获取生产员工详细信息
     */
    @PreAuthorize(hasPermi = "mes:dispatchWorkers:query")
    @GetMapping(value = "/{dispatchWorkerUuid}")
    public AjaxResult getInfo(@PathVariable("dispatchWorkerUuid") String dispatchWorkerUuid)
    {
        return AjaxResult.success(mesDispatchWorkersService.selectMesDispatchWorkersByDispatchWorkerUuid(dispatchWorkerUuid));
    }

    /**
     * 新增生产员工
     */
    @PreAuthorize(hasPermi = "mes:dispatchWorkers:add")
    @Log(title = "生产员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesDispatchWorkers mesDispatchWorkers)
    {
        return toAjax(mesDispatchWorkersService.insertMesDispatchWorkers(mesDispatchWorkers));
    }

    /**
     * 修改生产员工
     */
    @PreAuthorize(hasPermi = "mes:dispatchWorkers:edit")
    @Log(title = "生产员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesDispatchWorkers mesDispatchWorkers)
    {
        return toAjax(mesDispatchWorkersService.updateMesDispatchWorkers(mesDispatchWorkers));
    }

    /**
     * 删除生产员工
     */
    @PreAuthorize(hasPermi = "mes:dispatchWorkers:remove")
    @Log(title = "生产员工", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dispatchWorkerUuids}")
    public AjaxResult remove(@PathVariable String[] dispatchWorkerUuids)
    {
        return toAjax(mesDispatchWorkersService.deleteMesDispatchWorkersByDispatchWorkerUuids(dispatchWorkerUuids));
    }
}